package com.huangmb.anymark.app.api.mock;

import com.huangmb.androidlib.utils.Logger;
import com.huangmb.androidlib.utils.PreferencesUtils;
import com.huangmb.anymark.app.app.AnyMarkApplication;
import com.huangmb.anymark.app.model.Category;
import com.huangmb.anymark.app.model.Position;
import com.huangmb.anymark.app.model.UserMarker;

import java.util.*;

/**
 * 模拟数据中心
 * @author hmb
 * @version 1.0
 * @since 2016/4/24 15:03
 */
public class DataMock {
    private static Map<String, UserMarker> data = new HashMap<>();
    private static Map<String,String> typeMap = new HashMap<>();
    private static List<String> list = new ArrayList<>();
    public static int maxId = 0;
    static {
        list.add(UserMarker.TYPE_SCHEDULE);
        list.add(UserMarker.TYPE_LIVE);
        list.add(UserMarker.TYPE_STORE);
        list.add(UserMarker.TYPE_SCENERY);

        typeMap.put(UserMarker.TYPE_LIVE,"生活");
        typeMap.put(UserMarker.TYPE_SCENERY,"景点");
        typeMap.put(UserMarker.TYPE_SCHEDULE,"行程");
        typeMap.put(UserMarker.TYPE_STORE,"店铺");

        //模拟50组数据
        String lat = PreferencesUtils.getString(AnyMarkApplication.getInstance(), "latitude", null);
        String lon = PreferencesUtils.getString(AnyMarkApplication.getInstance(), "longitude", null);
        double curLat = 32.0256650000;
        double curLon = 118.8570770000;
        if (lat != null && lon != null) {
            try {

                curLat = Double.valueOf(lat);
                curLon = Double.valueOf(lon);
            } catch (Exception e) {
                //
            }
        }

        Random random = new Random();
        for (int i = 0; i < 50; i++) {
            String id = "" + i;
            maxId = i;
            double latitude = curLat + (random.nextDouble() * 0.01) * (random.nextInt(2) == 0 ? 1.0 : -1.0);
            double longitude = curLon + (random.nextDouble() * 0.01) * (random.nextInt(2) == 0 ? 1.0 : -1.0);
            Logger.d("坐标",latitude + " "+ longitude);
            String address = String.format("%s:%.4f-%.4f", "这里是", latitude, longitude);
            String type = list.get(random.nextInt(list.size()));
            String title = typeMap.get(type) + i;
            UserMarker item = new UserMarker();
            item.setId(id);
            item.setTitle(title);
            item.setLatitude(latitude);
            item.setLongitude(longitude);
            item.setAddress(address);
            Category category = new Category();
            category.setName(type);
            item.setCategory(category);
            data.put(id, item);
        }
    }

    public static Map<String,UserMarker> getData(){
        return data;
    }
    public static Map<String, String> getTypes(){
        return typeMap;
    }

}
